/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.yy.bugzillahelp.ui.detail;

import com.yy.bugzillahelp.MainFrame;
import com.yy.bugzillahelp.action.BugAction;
import com.yy.bugzillahelp.data.BugCommentData;
import com.yy.bugzillahelp.data.BugDetailData;
import com.yy.bugzillahelp.data.server.ServerData;
import com.yy.bugzillahelp.db.BugzillaHelpDB;
import com.yy.bugzillahelp.tool.SQLTool;
import java.awt.BorderLayout;
import java.sql.Connection;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author hualun-alan
 */
public class BugDetailPanel extends javax.swing.JPanel {

    private ServerData connectData;

    public BugDetailPanel(ServerData connectData) {
        this.connectData = connectData;
        initComponents();
    }

    public void show(String id) {
        Connection con = BugzillaHelpDB.getConnection();
        BugDetailData detailData = BugAction.searchById(con, id, connectData.getId());
        SQLTool.closeConnection(con);

        jlTitle.setText(detailData.getBugId() + " - " + detailData.getShortDesc());
        jlReporter.setText(detailData.getReporter());
        jlAssignedTo.setText(detailData.getAssignedTo());
        jlComponent.setText(detailData.getComponent());
        jlProduct.setText(detailData.getProduct());
        jlPriority.setText(detailData.getPriority());
        jlServity.setText(detailData.getSeverity());
        jlResolution.setText(detailData.getResolution());
        jlStatus.setText(detailData.getStatus());
        jlVersion.setText(detailData.getVersion());
        jlCreateTime.setText(detailData.getCreateTime());
        jlModifyTime.setText(detailData.getModifyTime());

        //<editor-fold defaultstate="collapsed" desc="不停的使用BorderLayout.North压缩空间放置Comment面板">
        JPanel jPanel = new JPanel(new BorderLayout());
        JPanel jpCenterTemp = jPanel;
        for (BugCommentData bugCommentData : detailData.getDescDatas()) {
            BugCommentPanel commentPanel = new BugCommentPanel();
            commentPanel.setCommentData(bugCommentData);

            jpCenterTemp.add(commentPanel, BorderLayout.NORTH);
            JPanel jpTemp = new JPanel(new BorderLayout());
            jpCenterTemp.add(jpTemp, BorderLayout.CENTER);
            jpCenterTemp = jpTemp;
        }
        jpComments.add(jPanel);
        jpComments.revalidate();
        //</editor-fold>
    }

    public static void main(String[] args) {
        JFrame jFrame = new JFrame("Bug List Panel");
        BugDetailPanel bugDetailPanel = new BugDetailPanel(MainFrame.CONNECT_DATA);
        bugDetailPanel.show("30");
        jFrame.getContentPane().add(bugDetailPanel);
        jFrame.setSize(800, 600);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setLocationRelativeTo(null);
        jFrame.setVisible(true);
    }

    /**
     * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jpNorth = new javax.swing.JPanel();
        jlTitle = new javax.swing.JLabel();
        jpContext = new javax.swing.JPanel();
        jpDetail = new javax.swing.JPanel();
        jpReporter = new javax.swing.JPanel();
        jlReporter1 = new javax.swing.JLabel();
        jlReporter = new javax.swing.JLabel();
        jpAssignedTo = new javax.swing.JPanel();
        jlAssignedTo1 = new javax.swing.JLabel();
        jlAssignedTo = new javax.swing.JLabel();
        jpCreateTime = new javax.swing.JPanel();
        jlCreateTime1 = new javax.swing.JLabel();
        jlCreateTime = new javax.swing.JLabel();
        jpModifyTime = new javax.swing.JPanel();
        jlModifyTime1 = new javax.swing.JLabel();
        jlModifyTime = new javax.swing.JLabel();
        jpProduct = new javax.swing.JPanel();
        jlProduct1 = new javax.swing.JLabel();
        jlProduct = new javax.swing.JLabel();
        jpComponent = new javax.swing.JPanel();
        jlComponent1 = new javax.swing.JLabel();
        jlComponent = new javax.swing.JLabel();
        jpVersion = new javax.swing.JPanel();
        jlVersion1 = new javax.swing.JLabel();
        jlVersion = new javax.swing.JLabel();
        jp1 = new javax.swing.JPanel();
        jpStatus = new javax.swing.JPanel();
        jlStatus1 = new javax.swing.JLabel();
        jlStatus = new javax.swing.JLabel();
        jpResolution = new javax.swing.JPanel();
        jlResolution1 = new javax.swing.JLabel();
        jlResolution = new javax.swing.JLabel();
        jpPriority = new javax.swing.JPanel();
        jlPriority1 = new javax.swing.JLabel();
        jlPriority = new javax.swing.JLabel();
        jpServity = new javax.swing.JPanel();
        jlServity1 = new javax.swing.JLabel();
        jlServity = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jpComments = new javax.swing.JPanel();
        jpWest = new javax.swing.JPanel();
        jpEast = new javax.swing.JPanel();

        setLayout(new java.awt.BorderLayout());

        jpNorth.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(102, 102, 102)));
        jpNorth.setPreferredSize(new java.awt.Dimension(400, 30));
        jpNorth.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        jlTitle.setFont(new java.awt.Font("宋体", 1, 18)); // NOI18N
        jpNorth.add(jlTitle);

        add(jpNorth, java.awt.BorderLayout.NORTH);

        jpContext.setLayout(new java.awt.BorderLayout());

        jpDetail.setBorder(javax.swing.BorderFactory.createMatteBorder(0, 0, 1, 0, new java.awt.Color(102, 102, 102)));
        jpDetail.setPreferredSize(new java.awt.Dimension(360, 100));
        jpDetail.setLayout(new java.awt.GridLayout(0, 2));

        jpReporter.setLayout(new java.awt.BorderLayout());

        jlReporter1.setText("报告人　：");
        jpReporter.add(jlReporter1, java.awt.BorderLayout.WEST);
        jpReporter.add(jlReporter, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpReporter);

        jpAssignedTo.setLayout(new java.awt.BorderLayout());

        jlAssignedTo1.setText("委托人　：");
        jpAssignedTo.add(jlAssignedTo1, java.awt.BorderLayout.WEST);
        jpAssignedTo.add(jlAssignedTo, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpAssignedTo);

        jpCreateTime.setLayout(new java.awt.BorderLayout());

        jlCreateTime1.setText("创建时间：");
        jpCreateTime.add(jlCreateTime1, java.awt.BorderLayout.WEST);
        jpCreateTime.add(jlCreateTime, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpCreateTime);

        jpModifyTime.setLayout(new java.awt.BorderLayout());

        jlModifyTime1.setText("修改时间：");
        jpModifyTime.add(jlModifyTime1, java.awt.BorderLayout.WEST);
        jpModifyTime.add(jlModifyTime, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpModifyTime);

        jpProduct.setLayout(new java.awt.BorderLayout());

        jlProduct1.setText("产　　品：");
        jpProduct.add(jlProduct1, java.awt.BorderLayout.WEST);
        jpProduct.add(jlProduct, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpProduct);

        jpComponent.setLayout(new java.awt.BorderLayout());

        jlComponent1.setText("组　　件：");
        jpComponent.add(jlComponent1, java.awt.BorderLayout.WEST);
        jpComponent.add(jlComponent, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpComponent);

        jpVersion.setLayout(new java.awt.BorderLayout());

        jlVersion1.setText("版　　本：");
        jpVersion.add(jlVersion1, java.awt.BorderLayout.WEST);
        jpVersion.add(jlVersion, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpVersion);

        javax.swing.GroupLayout jp1Layout = new javax.swing.GroupLayout(jp1);
        jp1.setLayout(jp1Layout);
        jp1Layout.setHorizontalGroup(
            jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 180, Short.MAX_VALUE)
        );
        jp1Layout.setVerticalGroup(
            jp1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 16, Short.MAX_VALUE)
        );

        jpDetail.add(jp1);

        jpStatus.setLayout(new java.awt.BorderLayout());

        jlStatus1.setText("状　　态：");
        jpStatus.add(jlStatus1, java.awt.BorderLayout.WEST);
        jpStatus.add(jlStatus, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpStatus);

        jpResolution.setLayout(new java.awt.BorderLayout());

        jlResolution1.setText("解决方案：");
        jpResolution.add(jlResolution1, java.awt.BorderLayout.WEST);
        jpResolution.add(jlResolution, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpResolution);

        jpPriority.setLayout(new java.awt.BorderLayout());

        jlPriority1.setText("优先级　：");
        jpPriority.add(jlPriority1, java.awt.BorderLayout.WEST);
        jpPriority.add(jlPriority, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpPriority);

        jpServity.setLayout(new java.awt.BorderLayout());

        jlServity1.setText("紧急程度：");
        jpServity.add(jlServity1, java.awt.BorderLayout.WEST);
        jpServity.add(jlServity, java.awt.BorderLayout.CENTER);

        jpDetail.add(jpServity);

        jpContext.add(jpDetail, java.awt.BorderLayout.NORTH);

        jpComments.setLayout(new javax.swing.BoxLayout(jpComments, javax.swing.BoxLayout.Y_AXIS));
        jScrollPane1.setViewportView(jpComments);

        jpContext.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        add(jpContext, java.awt.BorderLayout.CENTER);

        jpWest.setPreferredSize(new java.awt.Dimension(20, 270));

        javax.swing.GroupLayout jpWestLayout = new javax.swing.GroupLayout(jpWest);
        jpWest.setLayout(jpWestLayout);
        jpWestLayout.setHorizontalGroup(
            jpWestLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        jpWestLayout.setVerticalGroup(
            jpWestLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 370, Short.MAX_VALUE)
        );

        add(jpWest, java.awt.BorderLayout.WEST);

        jpEast.setPreferredSize(new java.awt.Dimension(20, 270));

        javax.swing.GroupLayout jpEastLayout = new javax.swing.GroupLayout(jpEast);
        jpEast.setLayout(jpEastLayout);
        jpEastLayout.setHorizontalGroup(
            jpEastLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 20, Short.MAX_VALUE)
        );
        jpEastLayout.setVerticalGroup(
            jpEastLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 370, Short.MAX_VALUE)
        );

        add(jpEast, java.awt.BorderLayout.EAST);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jlAssignedTo;
    private javax.swing.JLabel jlAssignedTo1;
    private javax.swing.JLabel jlComponent;
    private javax.swing.JLabel jlComponent1;
    private javax.swing.JLabel jlCreateTime;
    private javax.swing.JLabel jlCreateTime1;
    private javax.swing.JLabel jlModifyTime;
    private javax.swing.JLabel jlModifyTime1;
    private javax.swing.JLabel jlPriority;
    private javax.swing.JLabel jlPriority1;
    private javax.swing.JLabel jlProduct;
    private javax.swing.JLabel jlProduct1;
    private javax.swing.JLabel jlReporter;
    private javax.swing.JLabel jlReporter1;
    private javax.swing.JLabel jlResolution;
    private javax.swing.JLabel jlResolution1;
    private javax.swing.JLabel jlServity;
    private javax.swing.JLabel jlServity1;
    private javax.swing.JLabel jlStatus;
    private javax.swing.JLabel jlStatus1;
    private javax.swing.JLabel jlTitle;
    private javax.swing.JLabel jlVersion;
    private javax.swing.JLabel jlVersion1;
    private javax.swing.JPanel jp1;
    private javax.swing.JPanel jpAssignedTo;
    private javax.swing.JPanel jpComments;
    private javax.swing.JPanel jpComponent;
    private javax.swing.JPanel jpContext;
    private javax.swing.JPanel jpCreateTime;
    private javax.swing.JPanel jpDetail;
    private javax.swing.JPanel jpEast;
    private javax.swing.JPanel jpModifyTime;
    private javax.swing.JPanel jpNorth;
    private javax.swing.JPanel jpPriority;
    private javax.swing.JPanel jpProduct;
    private javax.swing.JPanel jpReporter;
    private javax.swing.JPanel jpResolution;
    private javax.swing.JPanel jpServity;
    private javax.swing.JPanel jpStatus;
    private javax.swing.JPanel jpVersion;
    private javax.swing.JPanel jpWest;
    // End of variables declaration//GEN-END:variables
}
